<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.wenjie.shoprankmonitor.User" %>
<%@ page import="com.wenjie.shoprankmonitor.Key_monitor_list" %>
<%@ page import="com.wenjie.shoprankmonitor.Shop_result" %>
<%@ page import="com.wenjie.shoprankmonitor.PMF" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Test result operation</title>
</head>
<body>
<%
PersistenceManager pm = PMF.get().getPersistenceManager();
String query = "select from " + User.class.getName();
List<User> users = (List<User>) pm.newQuery(query).execute();
if (users.isEmpty()) {
	%><p>No user.</p><%
} else {
	List<Key_monitor_list> keys = users.get(0).getMonitor_keys();
	if (keys.isEmpty()) {
		%><p>No monitor key.</p><%
	} else {
		Key_monitor_list key = keys.get(0);
		List<Shop_result> results = key.getResults();
		
		// ----------------- list results ------------------
		%><p>Start display result...</p><%
		for (Shop_result result : results) {
			%><p><%=result.getDefault_url() %>, <%=result.getGood_title() %>, <%=result.getOwner_nick() %>,
			<%=result.getRank() %>, <%=result.getNum_id() %>, <%=result.getOwner_score() %>, <%=result.getTimestamp() %></p><%
		}
		%><p>Finish display result!</p><%
		// ------------------ add new result ------------------
		%><p>Start add result...</p><%
		key.addResult("url...", "name", "close", 17l, 50l, 1);
		%><p>Finish add result!</p><%
		// ------------------- update result -------------------
		%><p>Start update result...</p><%
		Shop_result result = results.get(results.size() - 1);
		result.setDefault_url("hee");
		result.setTimestamp();
		%><p>Finish update result!</p><%
		// ------------------- delete result --------------------
		%><p>Start delete result...</p><%
		key.delResult(0);
	}
}
pm.close();
%>
</body>
</html>